<template>
	<view class="container">
		<jy-quick-btns></jy-quick-btns>
		<view class="questionbank">
			<!-- title -->
			<view class="questionbank-title">
				<view class="questionbank-title-item" v-for="(item, index) in questionBankList" :key="index">
					<view @click="questionBankChange(index)" :class="{btna:btnnum == index}">{{item}}</view>
					<text :class="{_underline: btnnum == index}"></text>
				</view>
			</view>
<!-- 			<view v-if="btnnum==0">
				<view class="cpres">您在本次测评中的总分为{{totalscore}}</view>
				<view class="cpres">您在本次测评中的平均分为{{tallpjf}}</view>
			</view>
			<view v-else-if="btnnum==1">
				<view class="cpres">您的测评结果为{{yltext}}</view>
			</view>
			<view v-else>
				<view class="cpres">您本次测评分值最高的为{{max_shijuan}}</view>
			</view> -->
			<view id="nodata" v-if="nodata">
				<image src="../../../static/wudingdan.png" mode="aspectFit"></image>
			</view>
			<view class="questionbank-content">
				<!-- 我的考试-->
				<view class="myExam" >
					<view class="item" v-for='item in getMyExamList' :key='item.id'>
						<view class="left">
							<view class="title">{{ item.name }}</view>
							<view class="time" style="">
								<view><image src="../../../static/shijian.png" mode=""></image><text>用时: {{ item.duration }}秒</text></view>
								<view v-if="btnnum==0">
									<text class="score">总分: {{ item.score}}</text>
									<text class="score">平均分: {{ item.pjf}}</text>
								</view>
								<view v-else-if="btnnum==1">
									<text class="score">您的测评结果为{{item.yltext}}</text>
								</view>
								<view v-else-if="btnnum==2">
									<text class="score">分值最高的分类为{{item.maxitem.flname1}},分数为：{{item.maxitem.sum1}}</text>
								</view>
								<view v-else-if="btnnum==3">
									<text class="score">此测评的T值为{{item.tscore}}分</text>
								</view>
								<view v-else-if="btnnum==4">
									<text class="score">测评结果为{{item.score}}</text>
								</view>
								<text class="score">测评时间:{{item.create_time}}</text>
							</view>
							<view style="margin-top: 10rpx;">
								<view v-for="(item1,index1) in item.fldetail" :key="index1" style="padding: 10rpx 0;" v-if="btnnum!=4">
									<view style="color: green;">分类 {{ item1.flname}}</view>
									<view style="color: green;">得分明细：</view>
									<view style="margin-top: 10rpx;">
										<text style="margin-right: 10rpx;">共{{item1.result.qnum}}题</text>
										<text v-if="item.is_zfshow == 1">总分：{{item1.result.sum}}分，</text>
										<text v-if="item.is_pjfshow == 1">平均分：{{item1.result.pjf}}</text>
										<text v-if="item1.res_text && item1.res_text != ''" style="font-weight: 700;font-size: 30rpx;" :style=" item1.res_text == '不符合'?'color: royalblue;':'color: red;'">{{item1.res_text}}</text>
									</view>
									<button type="warn" style="background-color: #e91e63;" size="mini" @click="xieclick(item1.flms)">查看描述</button>
								</view>
							</view>
							<!-- 细分类描述 -->
							<view v-if="xieyishow" class="xyshow">
								<scroll-view  scroll-y="true" class="xieyi_scroll" @scrolltolower = "scrolltolower">
									<jyf-parser :html="xieyicontent" ></jyf-parser>
								</scroll-view>
								<view class="woyiread">
									<button type="primary" @click="readedbtn" >关闭</button>
								</view>
							</view>
						</view>
						<view class="right">
							<button v-if="btnnum==4" style="background-color: #e91e63;" type="default" size="mini" @click="xieclick(item.miaoshu)" >查看描述</button>
							<button type="default" size="mini" @click="navigate(item.id,'exam')" >查看考试</button>
						</view>
					</view>
				</view>
			</view>
		</view>
		
		
	</view>
</template>

<script>
	import {checkUserinfo} from '@/request/checkUserinfo'
	import jyfParser from "@/components/jyf-parser/jyf-parser";
	export default {
		components:{
			jyfParser
		},
		data() {
			return {
				questionBankList: ['症状自评','依恋测评','九型人格','明尼苏达','MBTI'],
				btnnum: 0,
				getMyExamList:[],
				over:[],
				noStart:'',
				userinfo:{},
				shiti:{},
				nodata:false,
				flid:'13,14',
				totalscore:'',
				tallpjf:'',
				yltext:'',
				max_shijuan:'',
				xieyishow:false,
				xieyicontent:'',
				maxitem:{},
				flname1:'',
				sum1:''
			};
		},
		onShow() {
			checkUserinfo()
			let userinfo=uni.getStorageSync('userinfo')
			this.userinfo = userinfo.userdata
			if(userinfo.userdata){
				this.getMyExam()
			}
		},
		methods: {
			scrolltolower(e){
				console.log('滚动对象',e);
				if(e.detail.direction == 'bottom'){
					console.log('滚动到底了');
					// this.readok = true;
				}
			},
			readedbtn(){
				this.xieyishow=false
			},
			xieclick(e) {
				this.xieyicontent = e;
				this.xieyishow=true
			},
			showms(ms){
				uni.showModal({
					title: '描述',
					content: ms,
					showCancel: false,
					cancelText: '',
					confirmText: '已阅',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			questionBankChange(e) {
				this.btnnum = e
				if(e == 0){
					this.flid = '13,14'
				}else if(e == 1){
					this.flid = '13,16'
				}else if(e == 2){
					this.flid = '13,15'
				}else if(e == 3){
					this.flid = '13,32'
				}
				else if(e == 4){
					this.flid = '13,33'
				}
				this.totalscore = 0;
				this.tallpjf = 0;
				this.getMyExamList=[];
				this.getMyExam();
			},
			navigate(id,param) {
				uni.navigateTo({
					url:'../examDetail/examDetail?id='+id+'&param='+param
				});
			},
			

			getMyExam(){
				const BASE_URL = uni.BASE_URL
				uni.request({
					url: BASE_URL+'index/exam/myExamList',
					data:{
						uid:this.userinfo.id,
						flid:this.flid
					},
					method:'POST',
					success:(res) =>{
						console.log(res.data.data);
						if(res.data.code==0){
							if(res.data.data.examlist && res.data.data.examlist.length>0){
								this.yltext = res.data.data.yltext?res.data.data.yltext:''
								this.totalscore = res.data.data.totalscore?res.data.data.totalscore:''
								this.tallpjf = res.data.data.tallpjf?res.data.data.tallpjf:''
								this.getMyExamList = res.data.data.examlist
								// this.flname1 = res.data.data.examlist[0].maxitem?res.data.data.examlist[0].maxitem.flname1:''
								// this.sum1 = res.data.data.examlist[0].maxitem?res.data.data.examlist[0].maxitem.sum1:''
								this.nodata=false
							}else{
								this.getMyExamList=[]
								this.nodata=true
							}
						}
					},
					fail:(res)=> {
						console.log(res.data);
					}
				});
			}
		}
	}
</script>

<style lang="less" scoped>
#nodata {
	width: 100%;
	height: 100vh;
	background-color: #fff;
	image {
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -70%);
	}
}
			.xyshow{
				background-color: rgba(7, 7, 7, .05);
				z-index: 9999;
				height:100vh;
				width: 100%;
				position: fixed;
				top:0;
				left: 0;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				.xieyi_scroll{
					width: 80%;
					height: 60%;
					background-color: #FFF;
					display: flex;
					align-items: center;
					justify-content: center;
					border-radius: 10upx;
					padding:20upx 15upx;
				}
				.woyiread{
					button{
						width: 300upx;
						font-size: 28upx;
					}
				}
				.scroll-Y{
					height: 80%;
				}
			}
.questionbank {
	.cpres{
		padding: 20rpx;
		font-size: 30rpx;
		font-weight: 700;
		letter-spacing: 5rpx;
	}
	&-title{
		height: 125upx;
		background-color: #fff;
		padding-top: 45upx;
		box-sizing: border-box;
		display: flex;
		justify-content: space-around;
		&-item {
			flex: 1;
			display: flex;
			flex-direction: column;
			align-items: center;
			view {
			font-size: 30upx;
			color: #575757;
			}
			.btna { // 需要追加到view上的class
				font-weight: 700;
				color: #131313;
			}
			._underline { // 需要追加到view下方的下划线class
				width: 70upx;
				height: 7upx;
				background-color: #2f77ff;
				border-radius: 5upx;
				margin-top: 15upx;
			}
		}
		
	}
	
	&-content {
		.myExam {
			padding: 20upx;
			
			.item{
				box-sizing: border-box;
				width: 700upx;
				background-color: white;
				border-radius: 10upx;
				display: flex;
				align-items: center;
				padding: 20upx;
				border-bottom: 1rpx solid #ddd;
				.left{
					box-sizing: border-box;
					width: 500upx;
					color: #333;
					font-size: 28upx;
					display: flex;
					flex-direction: column;
					.title{
						color: #000000;
					}
					.time{
						margin-top: 10upx;
						display: flex;
						flex-direction: column;
						image{
							width: 30upx;
							height: 30upx;
							margin-right: 10upx;
						}
					}
					.score{
						color: red;
						font-size: 28rpx;
						letter-spacing: 5rpx;
					}
				}
				.right{
					width: 200upx;
					text-align: center;
					button{
						border-radius: 25upx;
						background-color: rgb(46,159,253);
						color: white;
						letter-spacing: 5upx;
					}
				}
			}
		}
		
		
		
		.noStart {
			display: none;
			padding: 20upx 30upx;
			.item{
				box-sizing: border-box;
				width: 700upx;
				height: 200upx;
				background-color: white;
				border-radius: 10upx;
				display: flex;
				margin-bottom: 30upx;
				.left{
					box-sizing: border-box;
					width: 450upx;
					height: 200upx;
					// background-color: pink;
					padding: 30upx;
					line-height: 54upx;
					color: #333;
					font-size: 28upx;
					.title{
						color: #000000;
					}
					image{
						width: 30upx;
						height: 30upx;
						margin-right: 10upx;
						line-height: 30upx;
					}
					.time{
						color: #8a8a8a;
						margin-top: 10upx;
					}
					.score{
						margin-left: 20upx;
						color: #8a8a8a;
					}
				}
				.right{
					width: 250upx;
					height: 200upx;
					// background-color: red;
					line-height: 230upx;
					text-align: center;
					button{
						border-radius: 25upx;
						background-color: rgb(46,159,253);
						color: white;
						letter-spacing: 5upx;
					}
				}
			}
		}
		
		.dis{
			display: block;
		}
	}
}


</style>
